<?php

namespace App\Admin\Controllers;

use App\Admin\Renderable\JobPositionTab;
use App\Admin\Repositories\AreaJobPosition;
use App\Admin\Repositories\JobPositionRecommend;
use App\Models\AreaJobPositionModel;
use App\Models\JobpositionModel;
use App\Models\JobPositionRecommendModel;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class AreaJobPositionController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new AreaJobPosition(['jobPositionInfo']), function (Grid $grid) {
            $plaza_id = request()->get('plaza_id');
            $grid->model()->where('plaza_id',$plaza_id)->orderBy('sort');
            $grid->column('id');
            $grid->column('job_position_id');
            $grid->column('jobPositionInfo.position_name', '职位名称');
            $grid->column('sort', '排序')->editable(true);
            $grid->column('jobPositionInfo.salary', '薪资');
            $grid->column('jobPositionInfo.expected_num', '招聘人数');
            $grid->column('jobPositionInfo.recruit_num', '实际招聘人数');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->model()->setConstraints([
                'plaza_id' => $plaza_id,
            ]);
            //边框模式
            $grid->withBorder();
            //横向滚动条
            $grid->scrollbarX();
            // 禁用批量删除按钮
//            $grid->disableBatchDelete();
            // 禁用显示按钮
            $grid->disableViewButton();
//            $grid->disableRowSelector();
//            $grid->disableDeleteButton();
            $grid->disableEditButton();
            $grid->option('dialog_form_area', ['700px', '350px'])->enableDialogCreate(); //
        });
    }


    /**
     * @return Form
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    protected function form()
    {
        $plaza_id = request()->get('plaza_id');
        return Form::make(new AreaJobPosition(), function (Form $form) use ($plaza_id){
            $form->display('id');
            $notIds = AreaJobPositionModel::query()->where('plaza_id',$plaza_id)->pluck('job_position_id')->toArray();
            $form->multipleSelectTable('job_position_id','选择岗位')
                ->title('岗位选择')
                ->from(JobPositionTab::make()->payload(['notIds'=>$notIds]))
                ->model(JobpositionModel::class, 'id', 'position_name');
            $form->text('plaza_id')->default($plaza_id);
            $form->hidden('sort')->default(0);
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
